﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Eis51.CampanyCMS.Model.BaseInfoMng;
using Eis51.CampanyCMS.Business.BaseInfoMng;
using System.Data;
using Eis51.CampanyCMS.Model;

using Eis51.CampanyCMS.Business.OnlineService;
using Eis51.Web.Admin;

namespace Eis51.CampanyCMS.WebUI.Admin.Baseinfo
{
    public partial class homePicslist : BasePage
    {

        private string type
        {
            get
            {
                if (Request["type"] != null)
                {
                    return Request["type"];
                }
                return "F";
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                ShowData();
            }
        }
        private void ShowData()
        {
            string sql = "select * from Base_Home_Pics where TITLE like '%{0}%' and CREATEBY='{1}' and licd={2} and type='{3}'";
            sql = string.Format(sql, txtTitle.Text, AppContext.CurrentAdministrator.UserName, AppContext.LCID, this.type);
            DataTable dt = BaseChatToolsBLL.GetInstance().GetDataTable(sql);
            dgNews.Data = dt;
            dgNews.DataBind();
        }
        protected void btnAdd_Click(object sender, System.EventArgs e)
        {
            string url = "homepicsedit.aspx?SEQNO={0}&type={1}";
            url = string.Format(url, 0, this.type);
            Response.Redirect(url);
        }
        protected void dgNews_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case "Delete":

                    BaseHomePics obj = BaseHomePicsBLL.GetInstance().Get(new BaseHomePics.Key(int.Parse(e.Item.Cells[0].Text)));
                    BaseHomePicsBLL.GetInstance().DeleteObj(obj);
                    ShowData();
                    break;
                case "Modify":
                    string url = "homepicsedit.aspx?SEQNO={0}&type={1}";
                    url = string.Format(url, e.Item.Cells[0].Text, this.type);
                    Response.Redirect(url);
                    break;
                default:
                    break;
            }
        }
        protected void dgNews_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem ||
                e.Item.ItemType == ListItemType.Item)
            {
                LinkButton btnDelete = e.Item.FindControl("btnDelete") as LinkButton;
                LinkButton btnModify = e.Item.FindControl("btnModify") as LinkButton;
                if (btnDelete != null)
                {
                    btnDelete.Attributes.Add("onclick", "javascript:return confirm('确定要删除?');");
                }
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            ShowData();
        }

    }
}
